package java250114;

public class MySingleList250114 {
    class ListNode{
        public int val;
        public ListNode next;
        public ListNode(int val){
            this.val = val;
        }
    }
    public static ListNode head;
    public void show(){
        ListNode cur = head;
        while(cur!=null){
            System.out.print(cur.val+" ");
            cur = cur.next;
        }
        System.out.println();
    }
    public void addFirst(int data){
        ListNode node = new ListNode(99);
        node.next = head;
        head = node;
    }
    public static boolean chkPalindrome(){
        //利用快慢指针找到中间节点
        ListNode fast = head;
        ListNode slow = head;
        while(fast!=null && fast.next!=null){
            fast = fast.next.next;
            slow = slow.next;
        }
        //slow所指的位置就是中间节点
        //2，开始翻转
        ListNode cur = slow.next;
        while(cur!=null){
            ListNode curNext = cur.next;
            cur.next = slow;
            slow = cur;
            cur = curNext;
        }
        //此时翻转完成，开始判断是否为回文
        while(head!=slow){
            if(head.val!=slow.val){
                return false;
            }
            //针对偶数节点添加if
            if(head.next==slow){
                return true;
            }
            head = head.next;
            slow = slow.next;
        }
        return true;
    }
}
